package com.jh.user.repository.freeQuick;

import cn.jh.common.pay.jdpush.FreeQuickRequestType;
import com.jh.user.pojo.freeQuick.PayBarRequestOrder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 * @author Yichuan
 * @version 1.0
 */
@Repository
public interface PayBarRequestOrderRepository extends JpaRepository<PayBarRequestOrder, Long>,
        JpaSpecificationExecutor<PayBarRequestOrder> {

    /**
     * 根据流水号和商户号查找汇数请求订单信息
     *
     * @param requestNo 开店管家流水号
     * @param merchantNo 开店管家分配的商户号
     * @return 返回订单信息
     */
    @Query("select pbro from PayBarRequestOrder pbro where pbro.requestNo=:requestNo and pbro.merchantNo=:merchantNo")
    PayBarRequestOrder findByRequestNoAndMerchantNo(@Param("requestNo") String requestNo, @Param("merchantNo") String merchantNo);

    /**
     * 根据下游商户的流水号和请求类型查找开店管家请求订单信息
     *
     * @param outSerialNo 下游商户的流水号
     * @param requestType 请求类型
     * @return 返回订单信息
     */
    @Query("select pbro from PayBarRequestOrder pbro where pbro.outSerialNo=:outSerialNo and pbro.requestType=:requestType")
    PayBarRequestOrder findByOutSerialNoAndRequestType(@Param("outSerialNo") String outSerialNo, @Param("requestType") FreeQuickRequestType requestType);
}
